﻿<%@ WebService Language="C#" Class="SaveNewsService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Text;

[WebService(Namespace = "http://www.hzsis.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SaveNewsService : System.Web.Services.WebService
{

    [WebMethod]
    public int InsertNews(string token, string _Title, string _Body, string _AddedDate, string _CategoryId, string _FromSource, string _ReleaseDate)
    {
        if (token != "www.hzsis.com") { return 0; }
        StarTech.DBUtility.AdoHelper ado = StarTech.DBUtility.AdoHelper.CreateHelper("DB_GetNews");
        StringBuilder strSql = new StringBuilder();
        //strSql.Append("insert into T_News_Test_save(");
        strSql.Append("insert into T_News (");
        strSql.Append("Title,Body,AddedDate,CategoryId,FromSource,ReleaseDate)");
        strSql.Append(" values (");
        strSql.Append("@Title,@Body,@AddedDate,@CategoryId,@FromSource,@ReleaseDate)");
        SqlParameter[] parameter = {
            new SqlParameter("@Title",SqlDbType.VarChar,8000),
            new SqlParameter("@Body",SqlDbType.Text),
            new SqlParameter("@AddedDate",SqlDbType.DateTime),
            new SqlParameter("@CategoryId",SqlDbType.Int),
            new SqlParameter("@FromSource",SqlDbType.VarChar,8000),
            new SqlParameter("@ReleaseDate",SqlDbType.DateTime)
        };
        parameter[0].Value = _Title;
        parameter[1].Value = _Body;
        try
        {
            parameter[2].Value = Convert.ToDateTime(_AddedDate);
        }
        catch (Exception)
        {
            parameter[2].Value = DateTime.Now;
        }
        try
        {
            parameter[3].Value = Convert.ToInt32(_CategoryId);
        }
        catch (Exception)
        {
            parameter[3].Value = Convert.ToInt32(0);
        }
        parameter[4].Value = _FromSource;
        try
        {
            parameter[5].Value = Convert.ToDateTime(_ReleaseDate);
        }
        catch (Exception)
        {
            parameter[5].Value = DateTime.Now;
        }
        return ado.ExecuteSqlNonQuery(strSql.ToString(), parameter);
    }

}